Skip to content

[Rust] Send TransformSession options as JSON - #8658

Open
jrozner wants to merge 1 commit into
Vector35:devfrom
jrozner:rust-transform-session-options
Open

jrozner wants to merge 1 commit into
Vector35:devfrom
jrozner:rust-transform-session-options

Conversation

@jrozner

@jrozner jrozner commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Problem

The five Rust TransformSession constructors (new, new_with_mode, from_view, from_view_with_mode, from_context) take a &Settings and send settings.serialize_schema() as the session options. That string is the settings schema (groups, titles, types, defaults), not the values set on the instance. The core expects a JSON object of setting keys and values, which is what Python (json.dumps(options)) and the C++ default ("{}") send. The core ignores the schema, so per-session overrides such as files.container.excludedTransforms have no effect from Rust.

On dev, with a ZIP of two files and an override instance that excludes the Zip transform:

global: transform="Zip" children=2
override: transform="Zip" children=2

The override should give transform="" children=0.

Change

new, new_with_mode, from_view, from_view_with_mode and from_context now take options: Option<O> with O: IntoJson, like load_with_options. None sends {}. They return Option<Ref<TransformSession>>: None if the options can't be converted to JSON or the core returns no session, as load_with_options does. The doc of new describes the options format and has an example.

This is a breaking change. Callers pass None::<&str> or Some(json) instead of &settings and unwrap the result. The only caller in this repository, test_context_transform, is updated. I chose it over keeping &Settings because it matches load_with_options and the Python and C++ APIs. Keeping &Settings would need a wrapper for BNSerializeSettings (SettingsAutoScope), and per-session options would then have to live in a named Settings instance that is shared process-wide and carries values between sessions.

Testing

New rust/tests/transform_session.rs builds a two-file ZIP at test time, so there is no binary fixture. test_session_options checks that with None, new_with_mode and from_view_with_mode extract the ZIP (root transform Zip, 2 children), and that with {"files.container.excludedTransforms": ["Zip"]} they don't (no transform, 0 children). It passes on this branch.

The tests are in their own file because rust/tests/transform.rs registers MyDetectionTransform, which accepts any input of 4 bytes or more and would be applied to these sessions. On dev, running all of cargo test --test transform together already overflows the stack in test_context_transform for that reason; each test passes when run alone. This PR doesn't change that.

from_context sends the options too, but a session created from an existing context used that context's settings in my tests, so it isn't covered.

cargo fmt --check and cargo clippy -p binaryninja --all-features --lib --test transform --test transform_session are clean.

The `TransformSession` constructors took a `&Settings` and passed
`Settings::serialize_schema()` as the session options. That is the
settings schema (groups, titles, types, defaults), not the values set on
the instance, and the core expects a JSON object of setting keys and
values, which is what Python and C++ send. The core ignores the schema,
so per-session overrides such as `files.container.excludedTransforms`
had no effect from Rust.

`new`, `new_with_mode`, `from_view`, `from_view_with_mode` and
`from_context` now take `options: Option<O>` with `O: IntoJson`, the same
as `load_with_options`, and send `{}` for `None`. Like
`load_with_options`, they return `None` if the options can't be
converted to JSON.
@emesare
emesare self-requested a review October 15, 2026 20:28
@emesare emesare self-assigned this Oct 15, 2026
@emesare emesare added the Component: Rust API Issue needs changes to the Rust API label Oct 15, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Rust API Issue needs changes to the Rust API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants